package com.xpj.simulate;

import com.xpj.service.AbstractPreloadService;
import com.xpj.template.CacheTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.concurrent.Executor;

@Service
public class ProductPreloadService extends AbstractPreloadService<Product, String> {




    public ProductPreloadService(@Qualifier("preloadExecutor") Executor preloadExecutor, CacheTemplate cacheTemplate) {
        super(preloadExecutor, cacheTemplate);
    }

    @Override
    public String buildCacheKey(String pruductId) {
        return "product:" + pruductId;
    }

    @Override
    public Product loadById(String productId) {
        //模拟查询数据库
        return ProductDatabase.database.get(productId);
    }
}
